<?php
/**
 * Description of AdminInfo
 *
 * @author hoangle
 * @version 1.0
 * @release20120607
 */
class User {

//put your code here
    private $db;
    
    public function  __construct() {
        $this->db = Zend_Registry::get('db');
    }

    /**
     * @desc Insert account info
     * @param <array> $arrParams
     * @return true | false
     */
    public function insertUserInfo($arrParams) {
        try {
            $stmt = $this->db->prepare('CALL sp_insertAccountInfo(:p_username, :p_password,
                    :p_email, :p_fullname, :p_birthday, :p_address, :p_cellphone,
                    :p_activationkey);');
            $stmt->bindParam(':p_username', $arrParams['username'], PDO::PARAM_STR);
            $stmt->bindParam(':p_password', md5($arrParams['password']), PDO::PARAM_STR);
            $stmt->bindParam(':p_email', $arrParams['email'], PDO::PARAM_STR);
            $stmt->bindParam(':p_fullname', $arrParams['fullname'], PDO::PARAM_STR);
            $stmt->bindValue('p_birthday', $arrParams['birthday']);
            $stmt->bindValue('p_address', $arrParams['address']);
            $stmt->bindValue('p_cellphone', $arrParams['cellphone']);
            $stmt->bindValue('p_activationkey', $arrParams['activationkey']);
            $stmt->execute();
            $stmt->closeCursor();
            unset($stmt);
        }
        catch (Zend_Db_Exception $e) {
            throw new Zend_Exception($e->getMessage(), 11);
        }
        return true;
    }

    /**
     * @desc Get last insert ids
     * @return <arr> result
     */
    public function getLastInsertID() {
        try {
            $sql = "SELECT LAST_INSERT_ID()as userid FROM user";
            $stmt = $this->db->prepare($sql);
            $stmt->execute();
            $result = $stmt->fetch();
            $stmt->closeCursor();
            unset($stmt);
        }
        catch (Zend_Db_Exception $e) {
            throw new Zend_Exception($e->getMessage(), 11);
        }
        return $result;
    }

    /**
     * @desc Get data info user
     * @param <array> $arrParams
     * @return <array>
     */
    public function getUserInfo($arrParams) {
        try {
            $sql = "SELECT * FROM user WHERE acc_email=:p_email";
            $stmt = $this->db->prepare($sql);
            $stmt->bindParam(':p_email', $arrParams['email'], PDO::PARAM_STR);
            $stmt->execute();
            $rows = $stmt->fetch();
            $stmt->closeCursor();           
            unset($stmt);
        }
        catch (Zend_Db_Exception $e) {
            throw new Zend_Exception($e->getMessage(), 11);
        }
        return $rows;
    }

	/**
     * @desc Get data info user
     * @param <array> $arrParams
     * @return <array>
     */
    public function getUserHaveManyHonorPoint($arrParams) {
        try {
            $sql = "SELECT * FROM user ORDER BY honor_point DESC LIMIT " . $arrParams['limit'];
            $stmt = $this->db->prepare($sql);
            $stmt->execute();
            $rows = $stmt->fetchAll();
            $stmt->closeCursor();           
            unset($stmt);
        }
        catch (Zend_Db_Exception $e) {
            throw new Zend_Exception($e->getMessage(), 11);
        }
        return $rows;
    }
	
	/**
     * @desc Get data info user
     * @param <array> $arrParams
     * @return <array>
     */
    public function getUserSpecialist($arrParams) {
        try {
            $sql = "SELECT * FROM user WHERE is_special_list=1 LIMIT " . $arrParams['limit'];
            $stmt = $this->db->prepare($sql);
            $stmt->execute();
            $rows = $stmt->fetchAll();
            $stmt->closeCursor();           
            unset($stmt);
        }
        catch (Zend_Db_Exception $e) {
            throw new Zend_Exception($e->getMessage(), 11);
        }
        return $rows;
    }
	
}

?>
